﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMSUIMVC.DTO.EnterStorage;
using WMSUIMVC.DTO.ProductsType;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    public class EnterStorageController : Controller
    {
        protected readonly IConfiguration configuration;

        public EnterStorageController(IConfiguration configuration)
        {
            this.configuration = configuration;
        }


        /// <summary>
        /// 入库显示
        /// </summary>
        /// <returns></returns>
        public IActionResult EnterStorageShow()
        {
            return View();
        }
        /// <summary>
        ///财务显示
        /// </summary>
        /// <returns></returns>
        public IActionResult CaiGouShow()
        {
            return View();
        }
        [HttpGet]
        public async Task<ActionResult> EnterStorageAdd(CaiWuSelectDto ss)
        {
            HttpClientWrapper client = new HttpClientWrapper(ss.Token);
            string url = configuration["Url"] + "ckd/api/EnterStorages/GetWearthList?ProductsCode=" + ss.ProductsCode + "&ProductsName=" + ss.ProductsName;
            var response = await client.GetAsync(url);
            return Json(response);
        }
        /// <summary>
        /// 入库添加
        /// </summary>
        /// <returns></returns>
        public IActionResult EnterStorageCreate()
        {
            return View();
        }

        /// <summary>
        /// 入库添加
        /// </summary>
        /// <param name="ptc">产品分类添加参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> EnterStorageAdd(EnterStorageAddDto ptc)
        {
            HttpClientWrapper client = new HttpClientWrapper(ptc.Token);
            string url = configuration["Url"] + "ckx/api/EnterStorages/AddEnterStorage";
            var response = await client.PostAsync(url, ptc.model);
            return Json(response);
        }
        /// <summary>
        /// 入库显示
        /// </summary>
        /// <param name="ptc">产品分类添加参数</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> EnterStorageSelect(EnterStorageShowDto ss)
        {
            HttpClientWrapper client = new HttpClientWrapper(ss.Token);
            string url = configuration["Url"] + "ckd/api/EnterStorages/GetWarehouseList?StockCode=" + ss.StockCode + "&StockOrderType=" + ss.StockOrderType + "&StateSP=" + ss.StateSP + "&PageIndex=" + ss.PageIndex + "&PageSize=" + ss.PageSize + "&ProductsName=" + ss.ProductsName + "&ProductsCode=" + ss.ProductsCode;
            var response = await client.GetAsync(url);
            return Json(response);
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="pd">产品分类删除参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> EnterStorageDelete(EnterStorageDeleteDto pd)
        {
            HttpClientWrapper client = new HttpClientWrapper(pd.Token);
            string url = configuration["Url"] + "ckx/api/EnterStorages/DeleteEnter";
            var response = await client.PostAsync(url, pd.id);
            return Json(response);
        }

        /// <summary>
        /// 入库反填（查看详情）
        /// </summary>
        /// <param name="ptc">产品分类添加参数</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> EnterStorageSet(string Token, int id)
        {
            HttpClientWrapper client = new HttpClientWrapper(Token);
            string url = configuration["Url"] + "ckd/api/EnterStorages/GetEntsrStoragesList?StockId=" + id;
            var response = await client.GetAsync(url);
            return Json(response);
        }

        /// <summary>
        /// 入库修改
        /// </summary>
        /// <returns></returns>
        public IActionResult EnterStorageUpdate()
        {
            return View();
        }

        /// <summary>
        /// 入库修改
        /// </summary>
        /// <param name="ptc">产品分类添加参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> EnterStorageUpdate(EnterStorageUpdateDto ptc)
        {
            HttpClientWrapper client = new HttpClientWrapper(ptc.Token);
            string url = configuration["Url"] + "ckx/api/EnterStorages/UPdateEnter";
            var response = await client.PostAsync(url, ptc.model);
            return Json(response);
        }

        /// <summary>
        /// 入库修改
        /// </summary>
        /// <param name="ptc">产品分类添加参数</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> EnterStorageUpdateState(EnterStorageUpdateState ptc)
        {
            HttpClientWrapper client = new HttpClientWrapper(ptc.Token);
            string url = configuration["Url"] + "ckx/api/EnterStorages/UPdateStateEnter";
            var response = await client.PostAsync(url, ptc.model);
            return Json(response);
        }
    }
}
